package subraSoft.centaurus.gui.validators.impl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.netbeans.validation.api.Problems;
import org.netbeans.validation.api.Validator;

/**
 * Valida que el campo sea vacio o un dni valido (cualquier tipo de documento no solo DNI).
 * 
 * @author caeycae
 *
 */
public class CenDniValidaror implements Validator<String>
{	
	private Pattern p;

	public CenDniValidaror()
	{
		p = Pattern.compile("[0-9.]*");
	}

	@Override
	public boolean validate(Problems problems, String compName, String model)
	{
		if(model != null && !model.isEmpty())
		{
			Matcher m = p.matcher(model);
			if(!m.matches())
			{
				problems.add("El campo " + compName + " no es un telefono valido");
				return false;
			}
		}
		return true;
	}
}
